package com.itboye.sunsun.person.ui;

import com.itboye.sunsun.R;
import com.itboye.sunsun.application.App;
import com.itboye.sunsun.constants.NetPublicConstant;
import com.itboye.sunsun.constants.SPContants;
import com.itboye.sunsun.shop.ui.ShareFragment;
import com.itboye.sunsun.support.BaseActivity;
import com.itboye.sunsun.utils.SPUtils;

import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.Button;
import android.widget.ImageView;

public class JiangActivity extends BaseActivity implements OnClickListener {

	private WebView webview;
	private ImageView back;
	private Button share;
	String baseurl = NetPublicConstant.secondUrl+"/Webview/Index/invitationAward?";
	String url;
	private InviteShareFragment shareFragment;

	@Override
	protected void onCreate(Bundle arg0) {
		// TODO Auto-generated method stub
		super.onCreate(arg0);
		setContentView(R.layout.activity_jiang);
		setStatusBarColor(R.color.orange);
		webviewsettings();
	}

	public void webviewsettings() {

		String uid = "uid" + "=" + (String) SPUtils.get(App.ctx, null, SPContants.USER_ID, "");
		String password = "psw" + "=" + (String) SPUtils.get(App.ctx, null, SPContants.PASSWORD, "");

		url = baseurl + uid + "&" + password;
		webview.getSettings().setJavaScriptEnabled(true);
		webview.loadUrl(url);
		webview.setWebViewClient(new WebViewClient()

		{

			@Override
			public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
				// TODO Auto-generated method stub
				//super.onReceivedError(view, errorCode, description, failingUrl);
				view.loadUrl("file:///android_asset/nonet.html");
			}
		});
		// webview.postUrl(url, postData);
	}

	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.back:
			this.finish();
			break;
		case R.id.share:
			shareFragment=new InviteShareFragment();
			shareFragment.show(getSupportFragmentManager(), url);
			break;

		default:
			break;
		}

	}
	@Override
	public boolean onKeyDown(int keyCode, KeyEvent event) {
		if (keyCode == KeyEvent.KEYCODE_BACK) {
			if (webview.canGoBack()) {
				webview.goBack();
				return true;
			}

		}
		return super.onKeyDown(keyCode, event);
	}

}
